package TCP;

import java.io.*;
import java.net.Socket;

/*
客户端：数据来源于键盘输入，知道输入数据是886，发送数据结束
 */
public class ClientDemo02 {
    public static void main(String[] args) throws IOException {
        //创建客户端Socket对象
        //Socket(InetAddress, int port) 创建流套接字并将其连接到指定IP地址的指定端口号
//        Socket ds=new Socket(InetAddress.getByName("192.168.146.1"),10086);
        //Socket(String host, int port) 创建流套接字并将其连接到指定IP地址的指定端口号
        Socket s =new Socket("192.168.146.1",10086);

        //键盘录入
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        //封装输出流对象
        //OutputStream getOutputStream () 返回此套接字的输出流
//        OutputStream os = ds.getOutputStream();
//        os.write("hello,tcp".getBytes());
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));//将字节输出流封装成字符流数据

        String line;
        while ((line=br.readLine())!=null){
            if ("886".equals(br)){
                break;
            }else {
                //获取输出流数据
//                OutputStream os = ds.getOutputStream();
//                os.write(line.getBytes());
                 bw.write(line);
                 bw.newLine();
                 bw.flush();
            }
            s.close();
        }
        //

    }
}
